Skip to content

Conversation

@guw
Copy link

@guw guw commented Aug 24, 2025

js_binary should use the new runtime toolchain to avoid execution toolchain being leaked into target environments (eg., js_image_oci)

See bazel-contrib/rules_nodejs#3854

Depends on:

Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: yes
  • Breaking change (forces users to change their own code or config): no
  • Suggested release notes appear below: yes

Switched js_binary (and js_test) to start using the new runtime toolchain type introduced by rules_nodejs to better support cross-platform builds (eg., building arm64 container from amd64).

Test plan

  • Covered by existing test cases

@aspect-workflows
Copy link

aspect-workflows bot commented Aug 24, 2025

Test

All tests were cache hits

278 tests (100.0%) were fully cached saving 36s.


Test

e2e/bzlmod

All tests were cache hits

5 tests (100.0%) were fully cached saving 617ms.


Test

e2e/git_dep_metadata

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Test

e2e/gyp_no_install_script

All tests were cache hits

2 tests (100.0%) were fully cached saving 165ms.


Test

e2e/js_image_oci

All tests were cache hits

1 test (100.0%) was fully cached saving 6s.


Test

e2e/npm_link_package

⚠️ Buildkite build #9698 failed.


Test

e2e/npm_link_package-esm

⚠️ Buildkite build #9698 failed.


Test

e2e/npm_link_package-rerooted

⚠️ Buildkite build #9698 failed.


Test

e2e/npm_translate_lock

All tests were cache hits

3 tests (100.0%) were fully cached saving 508ms.


Test

e2e/npm_translate_lock_disable_hooks

All tests were cache hits

3 tests (100.0%) were fully cached saving 247ms.


Test

e2e/npm_translate_lock_empty

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Test

e2e/npm_translate_lock_exclude_package_contents

All tests were cache hits

1 test (100.0%) was fully cached saving 34ms.


Test

e2e/npm_translate_lock_multi

All tests were cache hits

2 tests (100.0%) were fully cached saving 164ms.


Test

e2e/npm_translate_lock_partial_clone

All tests were cache hits

1 test (100.0%) was fully cached saving 61ms.


Test

e2e/npm_translate_lock_replace_packages

All tests were cache hits

3 tests (100.0%) were fully cached saving 320ms.


Test

e2e/npm_translate_lock_subdir_patch

All tests were cache hits

1 test (100.0%) was fully cached saving 77ms.


Test

e2e/npm_translate_package_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Test

e2e/npm_translate_yarn_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Test

e2e/package_json_module

All tests were cache hits

1 test (100.0%) was fully cached saving 244ms.


Test

e2e/patch_from_repo

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Test

e2e/pnpm_lockfiles

All tests were cache hits

67 tests (100.0%) were fully cached saving 8s.


Test

e2e/pnpm_repo_install

All tests were cache hits

1 test (100.0%) was fully cached saving 2s.


Test

e2e/pnpm_workspace

All tests were cache hits

15 tests (100.0%) were fully cached saving 2s.


Test

e2e/pnpm_workspace_deps

All tests were cache hits

3 tests (100.0%) were fully cached saving 392ms.


Test

e2e/pnpm_workspace_rerooted

All tests were cache hits

15 tests (100.0%) were fully cached saving 2s.


Test

e2e/repo_mapping

All tests were cache hits

3 tests (100.0%) were fully cached saving 386ms.


Test

e2e/rules_foo

⚠️ Buildkite build #9698 failed.


Test

e2e/runfiles

All tests were cache hits

1 test (100.0%) was fully cached saving 96ms.


Test

e2e/stamped_package_json

All tests were cache hits

1 test (100.0%) was fully cached saving 44ms.


Test

e2e/vendored_node

⚠️ Buildkite build #9698 failed.

Failed tests (1)
//:test [k8-fastbuild]🔗

💡 To reproduce the test failures, run

bazel test //:test

Test

e2e/vendored_tarfile

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Test

e2e/verify_patches

All tests were cache hits

2 tests (100.0%) were fully cached saving 109ms.


Test

e2e/worker

All tests were cache hits

1 test (100.0%) was fully cached saving 35ms.


Test

e2e/workspace

All tests were cache hits

1 test (100.0%) was fully cached saving 35ms.


Buildifier      Format

@keith
Copy link
Contributor

keith commented Aug 26, 2025

nice, verified this fixes this case too #2328

@guw guw force-pushed the use_runtime_toolchain branch from 1390f08 to 3eb24e8 Compare October 27, 2025 08:59
@guw
Copy link
Author

guw commented Oct 27, 2025

I am left with the following issue when building:

>  bazel build --toolchain_resolution_debug='@@rules_nodejs~//nodejs:toolchain_type' //...

INFO: ToolchainResolution: Performing resolution of @@rules_nodejs~//nodejs:toolchain_type for target platform @@platforms//host:host
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_linux_amd64//:toolchain; mismatching values: linux, x86_64
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_linux_arm64//:toolchain; mismatching values: linux
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_linux_s390x//:toolchain; mismatching values: linux, s390x
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_linux_ppc64le//:toolchain; mismatching values: linux, ppc
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_darwin_amd64//:toolchain; mismatching values: x86_64
      ToolchainResolution:   Toolchain @@rules_nodejs~~node~nodejs_darwin_arm64//:toolchain is compatible with target plaform, searching for execution platforms:
      ToolchainResolution:     Compatible execution platform @@platforms//host:host
      ToolchainResolution:   All execution platforms have been assigned a @@rules_nodejs~//nodejs:toolchain_type toolchain, stopping
      ToolchainResolution: Recap of selected @@rules_nodejs~//nodejs:toolchain_type toolchains for target platform @@platforms//host:host:
      ToolchainResolution:   Selected @@rules_nodejs~~node~nodejs_darwin_arm64//:toolchain to run on execution platform @@platforms//host:host
INFO: ToolchainResolution: Performing resolution of @@rules_nodejs~//nodejs:toolchain_type for target platform @@platforms//host:host
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_linux_amd64//:toolchain; mismatching values: linux, x86_64
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_linux_arm64//:toolchain; mismatching values: linux
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_linux_s390x//:toolchain; mismatching values: linux, s390x
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_linux_ppc64le//:toolchain; mismatching values: linux, ppc
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_darwin_amd64//:toolchain; mismatching values: x86_64
      ToolchainResolution:   Toolchain @@rules_nodejs~~node~nodejs_darwin_arm64//:toolchain is compatible with target plaform, searching for execution platforms:
      ToolchainResolution:     Compatible execution platform @@platforms//host:host
      ToolchainResolution:   All execution platforms have been assigned a @@rules_nodejs~//nodejs:toolchain_type toolchain, stopping
      ToolchainResolution: Recap of selected @@rules_nodejs~//nodejs:toolchain_type toolchains for target platform @@platforms//host:host:
      ToolchainResolution:   Selected @@rules_nodejs~~node~nodejs_darwin_arm64//:toolchain to run on execution platform @@platforms//host:host
INFO: ToolchainResolution: Performing resolution of @@rules_nodejs~//nodejs:toolchain_type for target platform //js/private/test/image:linux_amd64
      ToolchainResolution:   Toolchain @@rules_nodejs~~node~nodejs_linux_amd64//:toolchain is compatible with target plaform, searching for execution platforms:
      ToolchainResolution:     Incompatible execution platform @@platforms//host:host; mismatching values: linux, x86_64
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_linux_arm64//:toolchain; mismatching values: aarch64
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_linux_s390x//:toolchain; mismatching values: s390x
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_linux_ppc64le//:toolchain; mismatching values: ppc
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_darwin_amd64//:toolchain; mismatching values: osx
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_darwin_arm64//:toolchain; mismatching values: osx, aarch64
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_windows_amd64//:toolchain; mismatching values: windows
      ToolchainResolution:   Rejected toolchain @@rules_nodejs~~node~nodejs_windows_arm64//:toolchain; mismatching values: windows, aarch64
      ToolchainResolution: No @@rules_nodejs~//nodejs:toolchain_type toolchain found for target platform //js/private/test/image:linux_amd64.
INFO: ToolchainResolution: Target platform @@platforms//host:host: Selected execution platform @@platforms//host:host, type @@rules_nodejs~//nodejs:toolchain_type -> toolchain @@rules_nodejs~~node~nodejs_darwin_arm64//:toolchain
INFO: ToolchainResolution: Target platform @@platforms//host:host: Selected execution platform @@platforms//host:host, type @@rules_nodejs~//nodejs:toolchain_type -> toolchain @@rules_nodejs~~node~nodejs_darwin_arm64//:toolchain
ERROR: /Users/gwagenknecht/Development/aspect-build/rules_js/js/private/test/image/BUILD.bazel:114:20: While resolving toolchains for target //js/private/test/image:js_image_layer_untransitioned (3f5e2da): No matching toolchains found for types @@rules_nodejs~//nodejs:toolchain_type.
To debug, rerun with --toolchain_resolution_debug='@@rules_nodejs~//nodejs:toolchain_type'
If platforms or toolchains are a new concept for you, we'd encourage reading https://bazel.build/concepts/platforms-intro.
ERROR: Analysis of target '//js/private/test/image:transition_js_image_layer' failed; build aborted: Analysis failed

@guw guw force-pushed the use_runtime_toolchain branch from 3eb24e8 to f997478 Compare October 27, 2025 10:29
@guw guw marked this pull request as ready for review October 27, 2025 10:30
toolchains = [
tar_lib.toolchain_type,
"@rules_nodejs//nodejs:toolchain_type",
config_common.toolchain_type("@rules_nodejs//nodejs:toolchain_type", mandatory = False), # for executing Node in our actions (must not be mandatory because it only available in 'exec' config)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmeum I had to make this non-mandatory. Can I get your opinion whether that is plausible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't been able to find where these toolchains are used. Could they just be dropped?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was assuming they are needed because _node_tool and js_binary needs them. Are you saying it can be removed here?

toolchains = [
tar_lib.toolchain_type,
"@rules_nodejs//nodejs:toolchain_type",
config_common.toolchain_type("@rules_nodejs//nodejs:toolchain_type", mandatory = False), # for executing Node in our actions (must not be mandatory because it only available in 'exec' config)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't been able to find where these toolchains are used. Could they just be dropped?

),
"_current_node": attr.label(
default = "@nodejs_toolchains//:resolved_toolchain",
"_node_tool": attr.label(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This attribute could be replaced with @rules_nodejs//nodejs:toolchain_type as that matches on the exec platform.

Copy link
Author

@guw guw Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the recommended approach?

I could replace:

    nodeinfo = ctx.attr._node_tool[platform_common.ToolchainInfo].nodeinfo
    ....

with:

    nodeinfo = ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo
    if hasattr(nodeinfo, "node"):
        node_exec = nodeinfo.node
    else:
        # TODO(3.0): drop support for deprecated toolchain attributes
        node_exec = nodeinfo.target_tool_path
    ctx.actions.run(
        inputs = inputs,
        arguments = [splitter.path],
        unused_inputs_list = unused_inputs,
        outputs = splitter_outputs,
        executable = node_exec,
        progress_message = "Computing Layer Groups %{label}",
        mnemonic = "JsImageLayerGroups",
    )

But how do I control selection based on exec then?

Copy link
Author

@guw guw Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh so, nodeinfo = ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo would always match the execution platform?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, since that's what we ask the toolchains registered for this type to do. That's the idiomatic approach to use tools.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just keep in mind that the ctx.actions.run call should set the toolchain parameter to the toolchain type used in the action (if there is a single one, which is the case here).

js_binary should use the new runtime toolchain to avoid execution toolchain being leaked into target environments (eg.,  js_image_oci)

See bazel-contrib/rules_nodejs#3854
@guw guw force-pushed the use_runtime_toolchain branch from f997478 to 6e15cc8 Compare October 27, 2025 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants